res = (2,2)

point = []


for i in range(5):
    row = list(map(int,input().split()))
    if 1 in row:
        point = [i,row.index(1)]
    
print(abs(point[0] - res[0])+ abs(point[-1] - res[-1]))